package com.git.bds.mr.login.controller;

import com.git.bds.mr.login.service.user.LoginService;
import com.git.bds.mr.result.R;
import com.git.bds.mr.util.validate.phone.Phone;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

/**
 * @author 成大事
 * @since 2022/9/25 18:16
 */
@Api(tags = "添加 管理")
@Slf4j
@Validated
@RestController
@RequestMapping("/register")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class RegisterController {

    private final LoginService loginService;

    /**
     * 注册
     * @param tel       手机号
     * @param pwd         密码
     * @param code     验证码
     * @return R
     */
    @ApiOperation("注册 通过手机号")
    @PostMapping("/registerByTel")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="phone",dataTypeClass = String.class,required=true,value="用户的手机号"),
            @ApiImplicitParam(paramType="query",name="pwd",dataTypeClass = String.class,required=true,value="用户的密码"),
            @ApiImplicitParam(paramType="query",name="smsCode",dataTypeClass = String.class,required=true,value="手机验证码")
    })
    public R<Boolean> registered(
            @RequestParam("phone") @NotBlank(message = "手机号不能为空") @Phone @Size(max = 11,min = 11) String tel,
            @RequestParam("pwd") @NotBlank(message = "密码不能为空") String pwd,
            @RequestParam("smsCode") @NotBlank(message = "短信验证码不能为空") String code
    ){
        return R.decide(loginService.register(tel, pwd, code));
    }

}
